<template>
  <div id="headBox" class="pageNormalBackground">
    <headerT title="预约产品" />
    <div class="headMarginTop boxMain">
      <div class="searchBox displayFlex">
        <div class="everyBlockBgcolor displayFlex search">
          <img src="/static/images/search.png" alt @click="getList" />
          <input
            v-model="needInfo.goods_name"
            @input="getList"
            placeholder="搜索商品"
          />

        </div>
        <div class="telSearch" @click="$tools.goPage('/writeYuyuePhone')">号码查找</div>
      </div>
      <div class="everyBlockBgcolor productMain">
        <div v-if="myYuyueList.length!=0">
          <div
            class="displayFlex productList"
            v-for="(item,index) in myYuyueList"
            :key="index"
            @click="toYuyueSuccess(item.id)"
          >
            <img
              v-if="item.good_info!=null && item.good_info.good_img.length!=0"
              :src="item.good_info.good_img[0].img_url"
              alt
            />
            <div class="productInfo">
              <div class="productTitle">{{item.good_info!=null ?item.good_info.goods_name:''}}</div>
              <div class="displayFlex productTime">
                <img src="/static/images/time.png" alt />
                <p>入住日期 {{item.appointment_date}}</p>
              </div>
              <div class="yuyueStatus">预约成功</div>
            </div>
          </div>
        </div>
        <div v-if="myYuyueList.length==0" class="noData">暂无数据</div>
      </div>
    </div>
  </div>
</template>

<script>
import headerT from "@/components/header";
import { appointmentOfMy } from "@/services/yuyueProduct";
export default {
  components: {
    headerT
  },
  name: "",

  data() {
    return {
      needInfo: {
        id: "",
        consume_code: "", //消费码
        goods_name: "", //商品名
        page: 1,
        pageSize: 10
      },
      totalPage: 0, //总页数
      myYuyueList: [], //我的预约列表
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll);
  },

  methods: {
    //前往预约成功页面
    toYuyueSuccess(id) {
      this.$tools.goPage_query('/yuyueSuccess',{yuyueId:id,yuyueType:1})
    },

    getList() {
      this.$vux.loading.show({
        text: "Loading"
      });
      this.$post(appointmentOfMy, this.needInfo)
        .then(res => {
          this.$vux.loading.hide();
          this.totalPage = res.data.last_page;
          if (this.needInfo.page == 1) {
            this.myYuyueList = res.data.data;
            this.needInfo.page = res.data.current_page;
          } else {
            this.myYuyueList = [...this.myYuyueList, ...res.data.data];
          }
        })
        .catch(error => {
          this.$vux.loading.hide();
        });
    },
    handleScroll() {
      //分页加载数据
      if (
        document.documentElement.scrollTop + window.innerHeight >=
        document.body.offsetHeight
      ) {
        if (this.needInfo.page >= this.totalPage) {
          return;
        } else {
          this.needInfo.page = this.needInfo.page + 1;
          this.getList();
        }
      }
    }
  }
};
</script>

<style lang="less" rel="stylesheet/less" type="text/css" scoped>
@colorRed: #f64135;
@fontsize32: 0.32rem;
#headBox {
  .boxMain {
    .searchBox {
      font-size: @fontsize32;
      padding: 0.42rem 0.44rem 0.37rem 0.74rem;
      .search {
        width: calc(~"100% - 2.6rem");
        height: 0.69rem;
        border-radius: 1.48rem;
        justify-content: space-between;
        padding: 0 0.3rem;
        img {
          width: 0.29rem;
          height: 0.29rem;
          display: block;
        }
        input {
          display: block;
          height: 100%;
          width: calc(~"100% - 1rem");
          padding: 0 0.2rem;
          border: none;
          &::-webkit-input-placeholder {
            color: #c8c8c8;
          }
        }
      }
      .telSearch {
        width: 2.2rem;
        color: #747474;
        text-align: right;
      }
    }

    .productMain {
      padding: 0 0.44rem 1.4rem 0.46rem;
      .productList {
        height: 3.23rem;
        border-bottom: 1px solid #ebebeb;
        img {
          display: block;
          width: 2.88rem;
          height: 2.44rem;
        }
        .productInfo {
          padding: 0 0.3rem;
          width: calc(~"100% - 3rem");
          .productTitle {
            height: 0.5rem;
            font-size: @fontsize32;
            color: #4e4e4e;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            overflow: hidden;
            word-break: break-all;
          }
          .productTime {
            font-size: 0.3rem;
            color: #9f9f9f;
            margin: 0.23rem 0 0.32rem 0;
            img {
              display: block;
              width: 0.38rem;
              height: 0.38rem;
            }
            p {
              padding: 0 0.2rem;
            }
          }
          .yuyueStatus {
            font-size: @fontsize32;
            color: #39e578;
          }
        }
      }
    }
  }
}
</style>
